public class reverse {

    //链表回文
    public static boolean reverseList(MyListNode listNode) {
        //找到中件节点
        MyListNode.ListNode slow = listNode.head;
        MyListNode.ListNode faster = listNode.head;
        while (faster != null && faster.next != null) {
            slow = slow.next;
            faster = faster.next.next;
        }
        MyListNode.ListNode cur = slow.next;
        while (cur != null) {//反转
            MyListNode.ListNode curN = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curN;
        }


        MyListNode.ListNode tmp = listNode.head;
        while (slow != tmp) {
            if (tmp.val != slow.val) {
                return false;
            }
            if (tmp.next == slow) {
                return true;
            }
            slow = slow.next;
            tmp = tmp.next;
        }
        return true;
    }

    public static void main(String[] args) {
        MyListNode hh = new MyListNode();
        hh.addEnd(2);
        hh.addEnd(2);
        hh.addEnd(1);
        hh.addEnd(1);
        hh.addEnd(2);
        hh.addEnd(2);
        hh.show();
        System.out.println(reverseList(hh));
    }
}
